<?php

namespace App\Http\Controllers;

use App\Models\Project;
use App\Models\ProjectHasExtra;
use Carbon\Carbon;
use Illuminate\Http\Request;

class HomeController extends Controller
{

    public function siteSettingData(): \Illuminate\Http\JsonResponse
    {
        $data = [
            'OPEN_START_TIME' => admin_setting("OPEN_START_TIME"),
            'OPEN_END_TIME' => admin_setting("OPEN_END_TIME"),
            'SHOW_PROJECT_TIME' => admin_setting("SHOW_PROJECT_TIME"),
            'DEPARTMENT_ROWS' => admin_setting("DEPARTMENT_ROWS"),
            'DEFAULT_DEPARTMENT_ICON' => admin_setting("DEFAULT_DEPARTMENT_ICON"),
            'SHOW_DAY_COUNT' => admin_setting("SHOW_DAY_COUNT"),
            'NOTIFY_BOX_TIME' => admin_setting("NOTIFY_BOX_TIME"),
        ];
        return response()->json([
            'code' => HTTP_OK,
            'msg' => 'OK',
            'data' => $data,
        ]);
    }

    public function getProjectDetail(Request $request)
    {
        $id = $request->get("id");
        if (!$id)
            return response()
                ->json([
                    'code' => HTTP_BAD_REQUEST,
                    'msg' => '错误的项目',
                ]);
        $id = explode(",", $id);
        $date = $request->get('date') ?: now();
        $date = Carbon::parse($date);
        $projectData = Project::getProjectsAndDetail($id,$date);

        /**
         * 返回该治疗当天的预约情况
         *
         *
         */

        foreach ($projectData as $project) {
            $project->getTimeResult($date);
        }

        return response()
            ->json([
                'code' => HTTP_OK,
                'msg' => "OK",
                'data' => $projectData,
            ]);

    }

    public function getProjectTimeRange()
    {

    }
}
